package com.bonc.modules.business.controller;

import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicReference;

import com.alibaba.fastjson.JSONObject;
import com.bonc.common.param.BaseParam;
import com.bonc.common.utils.*;
import com.bonc.modules.business.entity.*;
import com.bonc.modules.business.service.TbWorkOrderInfoService;
import com.bonc.modules.business.service.TbWorkOrderReplyService;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.*;

import com.bonc.modules.business.service.TbWorkOrderReproceeService;


/**
 * 工单再处理码表
 *
 * @author feiniao
 * @date 2021-10-11 11:15:48
 */
@RestController
@RequestMapping("business/tbworkorderreprocee")
public class TbWorkOrderReproceeController {
    @Autowired
    private TbWorkOrderReproceeService tbWorkOrderReproceeService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("business:tbworkorderreprocee:list")
    public Result list(@RequestParam Map<String, Object> params){
        PageUtils page = tbWorkOrderReproceeService.queryPage(params);

        return Result.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{identifier}")
    @RequiresPermissions("business:tbworkorderreprocee:info")
    public Result info(@PathVariable("identifier") String identifier){
		TbWorkOrderReproceeEntity tbWorkOrderReprocee = tbWorkOrderReproceeService.getById(identifier);

        return Result.ok().put("tbWorkOrderReprocee", tbWorkOrderReprocee);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("business:tbworkorderreprocee:save")
    public Result save(@RequestBody TbWorkOrderReproceeEntity tbWorkOrderReprocee){
		tbWorkOrderReproceeService.save(tbWorkOrderReprocee);

        return Result.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("business:tbworkorderreprocee:update")
    public Result update(@RequestBody TbWorkOrderReproceeEntity tbWorkOrderReprocee){
		tbWorkOrderReproceeService.updateById(tbWorkOrderReprocee);

        return Result.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("business:tbworkorderreprocee:delete")
    public Result delete(@RequestBody String[] identifiers){
		tbWorkOrderReproceeService.removeByIds(Arrays.asList(identifiers));

        return Result.ok();
    }

    /**
     * 工单再处理接口
     * @param tbCommonParamValue
     * @return
     */
    @ExceptionHandler(HttpRequestMethodNotSupportedException.class)
    @PostMapping("/ReprocessCSS")
    public ReplyCommon ReprocessCSS(@RequestBody @Validated(BaseParam.list.class) TbCommonParamInfoEntity tbCommonParamValue) throws IllegalAccessException, UnsupportedEncodingException, NoSuchAlgorithmException {
        ReplyCommon res = tbWorkOrderReproceeService.ReprocessCSS(tbCommonParamValue);
        return res;
    }

    /**
     * 省端到集团再处理
     */
    @RequestMapping("/ReprocessCSService")
    public Result getReprocessCSService(@RequestBody TbWorkOrderReproceeEntity tbWorkOrderReprocee){
        AtomicReference<String> res = tbWorkOrderReproceeService.postOrderReproceeService(tbWorkOrderReprocee);
        return Result.ok().put("data",res);
    }

}
